﻿using System.Collections.ObjectModel;

using TimeSpan.Services;

namespace TimeSpan.Views.Pages;

public partial class PresetTaskViewModel(WorkflowService workflow, IConfig<SpanTasksConfig> optionsConfig) : ObservableObject, INavigationAware {

    [ObservableProperty]
    private ObservableCollection<SpanTaskOption?>? _options = optionsConfig.Config.BindingObject;

    [RelayCommand]
    private void Edit(SpanTaskOption? option) {
        workflow.AddOrEditTaskOption.OnNext(option);
    }

    [RelayCommand]
    private void Start(SpanTaskOption option) {
        workflow.StartTask.OnNext(new(option));
    }
    
    [RelayCommand]
    private void Delete(SpanTaskOption option) {
        workflow.DeleteTaskOption.OnNext(option);
    }

    public void OnNavigateTo(object? data) {
        optionsConfig.Config.InitBindingObject();
        Options ??= optionsConfig.Config.BindingObject;
    }
}